package com.talkology.pilot.start;

import org.apache.catalina.connector.Connector;
import org.apache.coyote.http11.Http11NioProtocol;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.File;
import java.util.Properties;

@SpringBootApplication
@ComponentScan("com.talkology.pilot.teacher,com.talkology.pilot.student,com.weixin.pay," +
        "com.talkology.pilot.start,com.talkology.pilot.manager")
@MapperScan("com.talkology.pilot.database.dao")
//@EnableAutoConfiguration
@EnableTransactionManagement
public class PilotRestApplication {
    private static final Logger LOG = LoggerFactory.getLogger(PilotRestApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(PilotRestApplication.class, args);
    }

//    @Value("${https.port}")
//    private Integer port;
//
//    @Value("${https.ssl.key-store-password}")
//    private String key_store_password;
//
////    @Value("${https.ssl.key-password}")
////    private String key_password;
//
//    @Bean
//    public ServletWebServerFactory servletContainer() {
//        TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
//        tomcat.addAdditionalTomcatConnectors(createSslConnector()); // 添加http
//        return tomcat;
//    }
//
//    private Connector createSslConnector() {
//        Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
//        Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
//        try {
//            String aaa = "/opt/1750679_dev.talkology.cn.pfx";
//            String os = System.getProperty("os.name");
//            if(os.toLowerCase().startsWith("win")){
//                aaa = PilotRestApplication.class.getClassLoader().getResource("sample.jks").getPath();
//            }
//            File keystore = new File(aaa);
//            connector.setScheme("https");
//            connector.setSecure(true);
//            connector.setPort(port);
//            protocol.setSSLEnabled(true);
//            protocol.setKeystoreFile(keystore.getAbsolutePath());
//            protocol.setKeystorePass(key_store_password);
////            protocol.setKeyPass(key_password);
//            return connector;
//        } catch (Exception ex) {
//            throw new IllegalStateException("can't access keystore", ex);
//        }
//    }
}
